/*
 * NextAction.java
 *
 * Created on June 22, 2005, 8:33 PM
 *
 * To change this template, choose Tools | Options and locate the template under
 * the Source Creation and Management node. Right-click the template and choose
 * Open. You can then make changes to the template in the Source Editor.
 */
package com.bff.slimserver.musicjukebox.lib.actions;

import com.bff.bjj.utils.Resources;
import java.awt.event.ActionEvent;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.Action;
import org.bff.slimserver.SlimPlayer;
import org.bff.slimserver.exception.SlimConnectionException;

/**
 *
 * @author Bill
 */
public class MuteAction extends PlayerAction {
    
    /** Creates a new instance of StopAction */
    public MuteAction(SlimPlayer player) {
        super(player);        
        setIcon();
        putValue(Action.NAME, Resources.getMessage(Resources.LABEL_KEY.ACTION_MUTE_NAME));
        putValue(Action.MNEMONIC_KEY, Resources.getKeyEvent(Resources.KEYEVENT_KEY.ACTION_MINIMIZE));
        putValue(Action.ACCELERATOR_KEY, Resources.getKeystroke(Resources.KEYSTROKE_KEY.KEYSTROKE_MINIMIZE));
        putValue(Action.SHORT_DESCRIPTION, Resources.getMessage(Resources.LABEL_KEY.ACTION_MUTE_SHORT_DESC));
    }
    
    @Override
    public void actionPerformed(ActionEvent evt) {
        try {
            getPlayer().mute();
        } catch (SlimConnectionException ex) {
            Logger.getLogger(MuteAction.class.getName()).log(Level.SEVERE, null, ex);
        }
        setIcon();
    }

    private void setIcon() {
        try {
            if (!getPlayer().isMuted()) {
                putValue(Action.SMALL_ICON, Resources.getIcon(Resources.ICON_KEY.ACTION_VOLUME));
            } else {
                putValue(Action.SMALL_ICON, Resources.getIcon(Resources.ICON_KEY.ACTION_MUTE));
            }
        } catch (SlimConnectionException ex) {
            Logger.getLogger(MuteAction.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
